package com.mytest.example.gobrs.task.chain5;

import cn.hutool.core.util.ObjectUtil;
import com.gobrs.async.TaskSupport;
import com.gobrs.async.anno.Task;
import com.gobrs.async.task.AsyncTask;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;


@Slf4j
@Task(desc = "Chain5TaskA")
@Component
public class Chain5TaskA extends AsyncTask<Chain5Param1, String> {
    @Override
    public void prepare(Chain5Param1 o) {

    }

    @SneakyThrows
    @Override
    public String task(Chain5Param1 o, TaskSupport taskSupport) {
        log.info("Chain5TaskA timeout={}", o.getTimeout());
        try {
            if (ObjectUtil.isNotNull(o.getTimeout())) {
                TimeUnit.SECONDS.sleep(o.getTimeout());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "Chain5TaskA";
    }

    @Override
    public boolean nessary(Chain5Param1 o, TaskSupport taskSupport) {
        return true;
    }

    @Override
    public void onSuccess(TaskSupport taskSupport) {
        log.info("Chain5TaskA 执行完成");
        //如果当前任务执行成功后，里立即想执行一些操作，可以在此回调实现，如发送短信，消息通知等

    }

    @Override
    public void onFail(TaskSupport taskSupport) {
        log.error("Chain5TaskA 执行失败");
    }
}
